import React, { Suspense } from 'react'
import ErrorBoundary from '.'

const withRetry = (loadAction) => (props) => (
  <ErrorBoundary>
    {
      () => {
        const Component = React.lazy(loadAction)
        return (
          <Suspense>
            <Component {...props} />
          </Suspense>
        )
      }
    }
  </ErrorBoundary>
)

export default withRetry
